package com.ray.life;

import java.util.List;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Html;

import com.google.android.maps.ItemizedOverlay;

public class NewsItemizedOverlay extends ItemizedOverlay<NewsOverlayItem> {
    private List<NewsOverlayItem> mItems;
    private Context mContext;

    public NewsItemizedOverlay(final List<NewsOverlayItem> items, final Drawable defaultMarker, final Context context) {
        /** locate marker on right position */
        super(boundCenterBottom(defaultMarker));
        mItems = items;
        mContext = context;

        populate();
    }

    @Override
    protected NewsOverlayItem createItem(int i) {
        return mItems.get(i);
    }

    @Override
    public int size() {
        return mItems.size();
    }

    @Override
    protected boolean onTap(final int i) {
        News news = mItems.get(i).getNews();
        new AlertDialog.Builder(mContext).setTitle(news.getTitle()).setMessage(Html.fromHtml(news.getDesc())).setPositiveButton("OK", null).show();
        return true;
    }
}
